package com.xjmall.controller.portal;

import com.github.pagehelper.PageInfo;
import com.xjmall.common.ServerResponse;
import com.xjmall.service.IProductService;
import com.xjmall.vo.ProductDetailVo;
import com.xjmall.vo.ProductListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by An on 2017/5/17.
 */
@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    /**
     * 根据商品id查询商品详情
     * @param productId
     * @return
     */
    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse<ProductDetailVo> getDetail(Integer productId) {
        return iProductService.getProductDetail(productId);
    }

    /**
     * 根据商品分类id和关键字分页查询商品列表（排序）
     * @param keyword
     * @param categoryId
     * @param pageNum
     * @param pageSize
     * @param orderBy
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<PageInfo> getList(@RequestParam(value = "keyword",required = false)String keyword,
                                            @RequestParam(value = "categoryId",required = false)Integer categoryId,
                                            @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                            @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
                                            @RequestParam(value = "orderBy",defaultValue = "") String orderBy) {
        return iProductService.getProductByKeywordCategory(keyword, categoryId, pageNum, pageSize, orderBy);
    }

    /**
     * 新品上架商品列表
     * @return
     */
    @RequestMapping("newProductList.do")
    @ResponseBody
    public ServerResponse<List<ProductListVo>> getNewProductList() {
        return iProductService.selectNewProductList();
    }

    /**
     * 疯狂热卖商品列表
     * @return
     */
    @RequestMapping("hotProductList.do")
    @ResponseBody
    public ServerResponse<List<ProductListVo>> getHotProductList() {
        return iProductService.selectHotProductList();
    }
}
